package com.fyt.recover.order;

public class QuikSortbySwap {

   public static void sort (int[]arr,int low,int high){
       if(low<high){
           int pivot=partition(arr,low,high);
           sort(arr,low,pivot-1);
           sort(arr,pivot+1,high);

       }

   }
    //立即交换的实现方案   4 6 7
    public static int partition(int[]arr,int low,int high){
        int temp=arr[low];
        int x=low;
        while (low<high){
            while (low<high&&arr[high]>=temp) high--;
            while (low<high&&arr[low]<=temp) low++;
            exchange(arr,high,low);


        }
        exchange(arr,x,low);
        return low;

    }

        public static int[] exchange(int [] arr,int i,int j) {
       int temp;
       temp=arr[i];
       arr[i]=arr[j];
       arr[j]=temp;

       return arr;
    }

    public static void startSort(int [] arr){
         sort(arr,0,arr.length-1);


        for (int i = 0; i <arr.length ; i++) {
            System.out.println(arr[i]);
        }
    }
}
